package com.fdb.efp.loan.service.impl;

import java.util.List;
import java.util.Objects;

import com.fdb.efp.loan.service.domain.BdIntFeeDetailTemp;
import org.slf4j.Logger;
import org.slf4j.LoggerFactory;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;

import com.irdstudio.basic.framework.core.base.FrameworkService;
import com.fdb.efp.loan.service.dao.BdIntFeeDetailTempDao;
import com.fdb.efp.loan.service.facade.BdIntFeeDetailTempService;
import com.fdb.efp.loan.service.vo.BdIntFeeDetailTempVO;

/**
 * <p>
 * ServiceImpl: 手工减免息费明细分期临时表
 * <p>
 * 
 * @author ligm
 * @date 2019-03-04
 */
@Service("bdIntFeeDetailTempService")
public class BdIntFeeDetailTempServiceImpl implements BdIntFeeDetailTempService, FrameworkService {

	private static Logger logger = LoggerFactory.getLogger(BdIntFeeDetailTempServiceImpl.class);

	@Autowired
	private BdIntFeeDetailTempDao bdIntFeeDetailTempDao;

	/**
	 * 新增操作
	 */
	public int insertBdIntFeeDetailTemp(BdIntFeeDetailTempVO inBdIntFeeDetailTempVo) {
		logger.debug("当前新增数据为:" + inBdIntFeeDetailTempVo.toString());
		int num = 0;
		try {
			BdIntFeeDetailTemp bdIntFeeDetailTemp = new BdIntFeeDetailTemp();
			beanCopy(inBdIntFeeDetailTempVo, bdIntFeeDetailTemp);
			num = bdIntFeeDetailTempDao.insertBdIntFeeDetailTemp(bdIntFeeDetailTemp);
		} catch (Exception e) {
			logger.error("新增数据发生异常!", e);
			num = -1;
		}
		logger.debug("当前新增数据条数为:" + num);
		return num;
	}

	/**
	 * 删除操作
	 */
	public int deleteByPk(BdIntFeeDetailTempVO inBdIntFeeDetailTempVo) {
		logger.debug("当前删除数据条件为:" + inBdIntFeeDetailTempVo);
		int num = 0;
		try {
			BdIntFeeDetailTemp bdIntFeeDetailTemp = new BdIntFeeDetailTemp();
			beanCopy(inBdIntFeeDetailTempVo, bdIntFeeDetailTemp);
			num = bdIntFeeDetailTempDao.deleteByPk(bdIntFeeDetailTemp);
		} catch (Exception e) {
			logger.error("删除数据发生异常!", e);
			num = -1;
		}
		logger.debug("根据条件:" + inBdIntFeeDetailTempVo + "删除的数据条数为" + num);
		return num;
	}

	/**
	 * 更新操作
	 */
	public int updateByPk(BdIntFeeDetailTempVO inBdIntFeeDetailTempVo) {
		logger.debug("当前修改数据为:" + inBdIntFeeDetailTempVo.toString());
		int num = 0;
		try {
			BdIntFeeDetailTemp bdIntFeeDetailTemp = new BdIntFeeDetailTemp();
			beanCopy(inBdIntFeeDetailTempVo, bdIntFeeDetailTemp);
			num = bdIntFeeDetailTempDao.updateByPk(bdIntFeeDetailTemp);
		} catch (Exception e) {
			logger.error("修改数据发生异常!", e);
			num = -1;
		}
		logger.debug("根据条件:" + inBdIntFeeDetailTempVo + "修改的数据条数为" + num);
		return num;
	}

	/**
	 * 查询操作
	 */
	public BdIntFeeDetailTempVO queryByPk(BdIntFeeDetailTempVO inBdIntFeeDetailTempVo) {

		logger.debug("当前查询参数信息为:" + inBdIntFeeDetailTempVo);
		try {
			BdIntFeeDetailTemp queryBdIntFeeDetailTemp = new BdIntFeeDetailTemp();
			beanCopy(inBdIntFeeDetailTempVo, queryBdIntFeeDetailTemp);
			BdIntFeeDetailTemp queryRslBdIntFeeDetailTemp = bdIntFeeDetailTempDao.queryByPk(queryBdIntFeeDetailTemp);
			if (Objects.nonNull(queryRslBdIntFeeDetailTemp)) {
				BdIntFeeDetailTempVO outBdIntFeeDetailTempVo = beanCopy(queryRslBdIntFeeDetailTemp, new BdIntFeeDetailTempVO());
				logger.debug("当前查询结果为:" + outBdIntFeeDetailTempVo.toString());
				return outBdIntFeeDetailTempVo;
			} else {
				logger.debug("当前查询结果为空!");
			}
		} catch (Exception e) {
			logger.error("查询数据发生异常!", e);
		}
		return null;
	}

	/**
	 * 查询用户权限数据
	 */
	@SuppressWarnings("unchecked")
	public List<BdIntFeeDetailTempVO> queryAll(BdIntFeeDetailTempVO bdIntFeeDetailTempVo) {

		logger.debug("当前查询本人所属数据信息的参数信息为:");
		List<BdIntFeeDetailTempVO> list = null;
		try {
			List<BdIntFeeDetailTemp> bdIntFeeDetailTemps = bdIntFeeDetailTempDao.queryAllByPage(bdIntFeeDetailTempVo);
			logger.debug("当前查询本人所属数据信息的结果集数量为:" + bdIntFeeDetailTemps.size());
			pageSet(bdIntFeeDetailTemps, bdIntFeeDetailTempVo);
			list = (List<BdIntFeeDetailTempVO>) beansCopy(bdIntFeeDetailTemps, BdIntFeeDetailTempVO.class);
		} catch (Exception e) {
			logger.error("数据转换出现异常!", e);
		}

		return list;

	}

	/**
	 * 查询当前机构权限数据
	 */
	@SuppressWarnings("unchecked")
	public List<BdIntFeeDetailTempVO> queryAllCurrOrg(BdIntFeeDetailTempVO bdIntFeeDetailTempVo) {

		logger.debug("当前查询本人所属机构数据信息的参数信息为:");
		List<BdIntFeeDetailTemp> bdIntFeeDetailTemps = bdIntFeeDetailTempDao.queryAllCurrOrgByPage(bdIntFeeDetailTempVo);
		logger.debug("当前查询本人所属机构数据信息的结果集数量为:" + bdIntFeeDetailTemps.size());
		List<BdIntFeeDetailTempVO> list = null;
		try {
			pageSet(bdIntFeeDetailTemps, bdIntFeeDetailTempVo);
			list = (List<BdIntFeeDetailTempVO>) beansCopy(bdIntFeeDetailTemps, BdIntFeeDetailTempVO.class);
		} catch (Exception e) {
			logger.error("数据转换出现异常!", e);
		}

		return list;

	}

	/**
	 * 查询当前机构及下属机构权限数据
	 */
	@SuppressWarnings("unchecked")
	public List<BdIntFeeDetailTempVO> queryAllCurrDownOrg(BdIntFeeDetailTempVO bdIntFeeDetailTempVo) {

		logger.debug("当前查询本人所属机构及以下数据信息的参数信息为:");
		List<BdIntFeeDetailTemp> bdIntFeeDetailTemps = bdIntFeeDetailTempDao.queryAllCurrDownOrgByPage(bdIntFeeDetailTempVo);
		logger.debug("当前查询本人所属机构及以下数据信息的结果集数量为:" + bdIntFeeDetailTemps.size());
		List<BdIntFeeDetailTempVO> list = null;
		try {
			pageSet(bdIntFeeDetailTemps, bdIntFeeDetailTempVo);
			list = (List<BdIntFeeDetailTempVO>) beansCopy(bdIntFeeDetailTemps, BdIntFeeDetailTempVO.class);
		} catch (Exception e) {
			logger.error("数据转换出现异常!", e);
		}
		return list;
	}

	/**
	 * 
	 * 分页查询【手工减免息费明细临时表】 <br>
	 * 0.1:ludayong:2019年3月23日 下午12:11:04:新增 <br>
	 * 
	 * @author ludayong
	 * @since 2019年3月23日 下午12:11:04
	 * @date 2019年3月23日 下午12:11:04
	 * @version 0.1
	 */
	@SuppressWarnings("unchecked")
	@Override
	public List<BdIntFeeDetailTempVO> queryByPage(BdIntFeeDetailTempVO BdIntFeeDetailTempVO) {
		String msg1 = "分页查询手工减免息费明细临时表";
		logger.debug(msg1, "message {}");
		List<BdIntFeeDetailTempVO> list = null;
		try {
			List<BdIntFeeDetailTemp> BdIntFeeDetailTemps = bdIntFeeDetailTempDao.queryByPage(BdIntFeeDetailTempVO);
			list = (List<BdIntFeeDetailTempVO>) beansCopy(BdIntFeeDetailTemps, BdIntFeeDetailTempVO.class);

		} catch (Exception e) {
			logger.error("查询数据发生异常!", e);

		}
		if(list != null) {
			String msg2 = "查询的数据为大小为 " + list.size();
			logger.debug(msg2, "message {}");
		}
		return list;
	}

	/**
	 * 
	 * 统计【手工减免息费明细临时表】数据量 <br>
	 * 0.1:ludayong:2019年3月23日 下午12:11:10:新增 <br>
	 * 
	 * @author ludayong
	 * @since 2019年3月23日 下午12:11:10
	 * @date 2019年3月23日 下午12:11:10
	 * @version 0.1
	 */
	@Override
	public int queryCount() {
		String msg1 = "查询【手工减免息费明细临时表】表中数据量大小";
		logger.debug(msg1, "message {}");
		int num = 0;
		try {
			num = bdIntFeeDetailTempDao.queryCount();
		} catch (Exception e) {
			String msg2 = "查询【手工减免息费明细临时表】表中数据量大小出错" + e;
			logger.debug(msg2, "message {}");
			num = -1;
		}
		return num;
	}
}
